import java.util.Collections;
import java.util.PriorityQueue;

public class TopK {
    public static  int test1(int[] nums,int k){
        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());
        int size = nums.length;
        for (int i = 0 ; i < size ; i++){
            maxHeap.add(nums[i]);
        }
        int num = 0;
        for (int i = 0 ; i < k ; i++){
          if (i == k -1){
              num = maxHeap.poll();
              break;
          }
          maxHeap.poll();
        }
        return num;
    }

    public static void main(String[] args) {
       int[] nums = {3,2,1,5,6,4};
       System.out.println(test1(nums,2));
    }
}
